package com.bos.controller;

import com.bos.service.LogsService;
import com.bos.common.PageData;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LogsController {
    @Autowired
    @Qualifier("logsServiceImpl")
    LogsService logsService;

    @RequestMapping(value = "findLogs")
    public String fingLogsAll(Model model, HttpServletRequest request) {
        //获取页面的当前页数和页面大小,默认是第一页
        String pageIndex = request.getParameter("pageNo");
        String setPageSize = request.getParameter("setPageSize");
        String leader = request.getParameter("leader");
        String logs = request.getParameter("logs");
        int pageNo = 1, pageSize = PageData.DEFAULTPAGESIZE;
        if (!Strings.isNullOrEmpty(pageIndex)) {
            pageNo = Integer.valueOf(pageIndex);
        }
        if (!Strings.isNullOrEmpty(setPageSize)) {
            pageSize = Integer.valueOf(setPageSize);
        }
        PageData log = logsService.findLogs(leader, logs, pageSize, pageNo);
        model.addAttribute("list", log);
        return "jsp/findLogs";
    }
}
